package com.woniuxy.processweb.controller;

import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.MyJwtUtil;
import com.woniuxy.core.util.PageInfo;
import com.woniuxy.processdao.model.ValidCardStep;
import com.woniuxy.processmodel.dto.ValidCardStepDto;
import com.woniuxy.processmodel.form.VenueLookValidCardStepForm;
import com.woniuxy.processservice.exception.ProcessException;
import com.woniuxy.processservice.service.ValidCardStepService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 有效期会员卡流程 前端控制器
 * </p>
 *
 * @author 冉杰
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/validCardStep")
@Api(tags = {"有效期会员卡进度记录接口"})
public class
ValidCardStepController {
    @Autowired
    private ValidCardStepService validCardStepService;

    @ApiOperation("新增有效期卡进度接口")//有效期卡订单生成时调用该接口
    @GetMapping("/add")
    public Result addValidCardStep(String orderNum){
        validCardStepService.addValidCardStep(orderNum);
        return Result.success("新增有效期卡进度成功");
    }
    @ApiOperation("根据id查询有效期卡进度接口")
    @GetMapping("/look")
    public Result lookValidCardStep(Integer stepId){
        ValidCardStep validCardStep = validCardStepService.lookValidCardStep(stepId);
        return Result.success("新增有效期卡进度成功",validCardStep);
    }
    @ApiOperation("根据订单号查询有效期卡进度接口")
    @GetMapping("/lookByOrderNum")
    public Result lookValidCardStepByOrderNum(Integer orderNum){
        ValidCardStep validCardStep = validCardStepService.lookValidCardStepByOrderNum(orderNum);
        return Result.success("查询有效期卡进度成功",validCardStep);
    }
    @ApiOperation("用户查询自己的有效期卡进度接口")
    @GetMapping("/userLook")
    public Result userLookValidCardStep(@RequestHeader String token){
        Integer userId = MyJwtUtil.getUserIdByKey(token, "userId");
        List<ValidCardStepDto> dtos = validCardStepService.userLookValidCardStep(userId);
        return Result.success("用户查询有效期卡进度成功",dtos);
    }

    @ApiOperation("商家查询自己的有效期卡进度接口")
    @PostMapping("/venueLook.venue")
    public Result venueLookValidCardStep(@RequestBody @Validated VenueLookValidCardStepForm form, BindingResult br, @RequestHeader String token){
        if(br.hasErrors()) throw new ProcessException(90001,"参数校验异常");
        Integer venueId = MyJwtUtil.getVenueIdByKey(token, "venueId");
        PageInfo<ValidCardStepDto> dtos = validCardStepService.venueLookValidCardStep(form,venueId);
        return Result.success("商家查询有效期卡进度成功",dtos);
    }



}

